【Paddle Tensor 第二期 API支持 0-size Tensor】Fix frobenius_norm to support 0-size tensor#72570
Merged
HydrogenSulfate merged 4 commits intoPaddlePaddle:developfrom May 14, 2025
Merged
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
fangfangssj
reviewed
May 1, 2025
Comment on lines
+30
to
+49
| auto xdim = x.dims(); | ||
|
|
||
| if (x.numel() == 0) { | ||
| std::set<int> axis_set; | ||
| for (int ax : axis.GetData()) { | ||
| if (ax < 0) { | ||
| ax += xdim.size(); | ||
| } | ||
| axis_set.insert(ax); | ||
| } | ||
|
|
||
| std::vector<int64_t> out_dims_vec; | ||
| for (int i = 0; i < xdim.size(); ++i) { | ||
| if (axis_set.find(i) == axis_set.end()) { | ||
| out_dims_vec.push_back(xdim[i]); | ||
| } else if (keep_dim) { | ||
| out_dims_vec.push_back(1); | ||
| } | ||
| } | ||
| out->Resize(phi::make_ddim(out_dims_vec)); |
Contributor
There was a problem hiding this comment.
形状推导已经在InferMeta中进行过了,可以使用out->dims()来获得,out已经是正确的形状了,不需要resize了,可以参考https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/api_contributing_guides/new_cpp_op_cn.html
Comment on lines
+30
to
+49
| bool reduce_all, | ||
| DenseTensor* out) { | ||
| if (x.numel() == 0) { | ||
| auto dim_x = x.dims(); | ||
| std::set<int> axis_set; | ||
| for (auto ax : dims.GetData()) { | ||
| if (ax < 0) ax += dim_x.size(); | ||
| axis_set.insert(ax); | ||
| } | ||
|
|
||
| std::vector<int64_t> out_dims_vec; | ||
| for (int i = 0; i < dim_x.size(); ++i) { | ||
| if (axis_set.count(i) == 0) { | ||
| out_dims_vec.push_back(dim_x[i]); | ||
| } else if (keep_dim) { | ||
| out_dims_vec.push_back(1); | ||
| } | ||
| } | ||
|
|
||
| // 正确调用 Full 初始化 |
test/legacy_test/test_norm_all.py
Outdated
|
|
||
| class API_NormTest(unittest.TestCase): | ||
| def test_basic(self): | ||
| paddle.enable_static() |
Contributor
There was a problem hiding this comment.
建议把paddle.enable_static()更换为with static_guard(),static_guard在utils.py中
Contributor
Author
|
按照@fangfangssj 的建议进行了如下修改:
测试结果: |
Comment on lines
+33
to
+47
| auto dim_x = x.dims(); | ||
| std::set<int> axis_set; | ||
| for (auto ax : dims.GetData()) { | ||
| if (ax < 0) ax += dim_x.size(); | ||
| axis_set.insert(ax); | ||
| } | ||
|
|
||
| std::vector<int64_t> out_dims_vec; | ||
| for (int i = 0; i < dim_x.size(); ++i) { | ||
| if (axis_set.count(i) == 0) { | ||
| out_dims_vec.push_back(dim_x[i]); | ||
| } else if (keep_dim) { | ||
| out_dims_vec.push_back(1); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
这里的形状推到应该可以去掉,执行这个函数之前,在ReduceIntArrayAxisInferMetaBase中应该已经计算完,并放到out->dims()里了
Contributor
Author
There was a problem hiding this comment.
谢谢,已经按照建议修改,在本地重新编译并通过了全部单测
GITD245
pushed a commit
to GITD245/Paddle
that referenced
this pull request
May 14, 2025
…0-size tensor (PaddlePaddle#72570) * [Tensor] Fix frobenius_norm to support 0-size tensor * [Tensor] Drop resize of fro-norm * [Tensor] Import utils with non-relative path * drop resize in gpu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
User Experience
PR Types
Bug fixes
Description
运行单元测试显示:
目前给fro-norm写的单测都能通过,basic_test也能通过了
剩下的报错都是nuclear-norm调用svd的错误,需要后续再调整svd以完整支持matrix-norm。
Issue: #69908
@HydrogenSulfate